package com.zch.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.base.action.CoreController;
import com.base.dao.model.Grid;
import com.base.dao.model.Ret;
import com.base.dialect.PaginationSupport;
import com.base.log.annotation.ControllerLog;
import com.base.util.JSONUtils;
import com.base.web.annotation.LoginFilter;
import com.item.daoEx.model.UserEx;
import com.item.service.UserService;
import com.item.util.QueryParams;
import com.zch.dao.model.ChatDeptUser;
import com.zch.service.ChatDeptUserService;

@RequestMapping("chatDeptUser")
@Controller
@LoginFilter
public class ChatDeptUserController extends CoreController{

	@Autowired
	private ChatDeptUserService chatDeptUserService;
	@Autowired
	private UserService userService;

	@RequestMapping("/list")
	@ResponseBody
	public String list(Integer page, Integer rows,String code){
		PaginationSupport.byPage(page, rows);
		QueryParams.Builder builder = QueryParams.newBuilder();
		builder.put("code", code);
		List<UserEx> list = userService.selectAdminChatUserList(builder);
		return JSONUtils.serialize(new Grid(PaginationSupport.getContext().getTotalCount(), list));
	}

	@RequestMapping("/save")
	@ResponseBody
	public String save(ChatDeptUser chatDeptUser){
		if (StringUtils.isBlank(chatDeptUser.getId())){
			chatDeptUserService.insert(chatDeptUser);
		}else{
			chatDeptUserService.updateByPrimaryKeySelective(chatDeptUser);
		}
		return JSONUtils.serialize(new Ret(0));
	}

	@RequestMapping("/findById")
	@ResponseBody
	public String find(String id){
		ChatDeptUser chatDeptUser = chatDeptUserService.selectByPrimaryKey(id);
		return JSONUtils.serialize(chatDeptUser);
	}

	@RequestMapping("/del")
	@ResponseBody
	public String del(String id){
		String[] ids = id.split(",");
		for (String str : ids){
			chatDeptUserService.deleteByPrimaryKey(str);
		}
		return JSONUtils.serialize(new Ret(0));
	}

}